<template>
  <div id="app">
        <router-view></router-view>
     <footermenu v-if="footerShow"></footermenu>
  </div>
</template>
<script>
    import Footermenu from 'components/Footermenu'
    import Vue from 'vue';
    import axios from 'axios';
    import '../../static/css/base.css'
    import {
        setAPIToken
    } from '../api'
    export default {
        components: {
            Footermenu,
        },
        data() {
            return {}
        },
        created() {
            var token = null;
            /* 开发环境 */
            if (process.env.NODE_ENV !== 'production') {
            	//登录账号信息
							//我的账号
            		 window.localStorage.setItem('token','VFdwVk5VMTZWWGhPYWxWNFdtcGthRTVFVlRWWlYwVjVUa2RSTkZsNlkzcFpWRkY1V1hwRmVVNTZaejA9');
                //window.localStorage.setItem('token', 'V1cxRk0wNHlUbXhhVkVVelRXcF"pNRTVFYUd0TlIwWm9XVEpGZUU1SFdtdFpWMDB6V2tSUk1WbDZXVDA9');
                //window.localStorage.setItem('token', 'V1cxSk5FMTZZekpPZW10NVRXMU9hVTVIV1RGUFZHdDNUMGRXYkU1Nll6Vk9WR2QzVFdwU2FVNHlVVDA9');
                //window.localStorage.setItem('token', 'VGtSb2JVOUVTVE5QVjFVMVdWUkdhazVIVlRCYVJHaHNUMGRXYWxsWFdtaE9ha3ByVFdwQk5VOUVaejA9');
                // setAPIToken(localStorage.getItem('token'));
                //教练账号
                window.localStorage.setItem('token','VFhwck0wMVVRVEJOYWs1clRWZEplRTVIU1RSTmFtYzBXbTFSZVU5VVZYbFpWRlUxVGxSWk5GcEVVVDA9');
                token = localStorage.getItem('token');
            }
            /* 线上环境 */
            if (process.env.NODE_ENV == 'production') {
                token = window.localStorage.getItem('token');
                console.log("线上环境 localStorage TOKEN:" + token);
                if ((token == null || token == '' || token == 'null') && (this.queryUrlParamByName('token') == null || this.queryUrlParamByName('token') == '')) {
                    var path = this.$route.fullPath;
                    var url = "https://login.shapejoy.com/wechat";
                    if (path !== "/") {
                        url = url + "?next=" + path;
                    }
                    window.location.replace(url); // 强制跳转登陆
                    return;
                } else {
                    var urlToken = this.queryUrlParamByName('token');
                    if (urlToken != null && urlToken != '') {
                        token = urlToken
                    }
                }
            }
            this.initApp(token); // 初始化App.vue
        },
        computed: {
            footerShow() {
                return this.$store.state.footer.show
            },
        },
        methods: {
            initApp(token) {
                var next = null;
                setAPIToken(token);
                var to = this.queryUrlParamByName('next');
                if (to != null && to != '') {
                    next = to;
                    this.$router.push(next);
                }
                // 拉取用户信息----是需要的
                this.$store.dispatch('GET_USER_INFO');
            },
            queryUrlParamByName(name) {
                var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        },
    }
</script>
<style>
    body {
        font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", STHeiti, "Microsoft Yahei", Tahoma, Simsun, sans-serif;
    }
    
    #app {
        margin-bottom: 50px!important;
        box-sizing: border-box;
        overflow: hidden;
    }
</style>